package com.yinhai.util;

public final class PYSiteFunction {
    
    public static SiteObj GetQuanPYSite(String separatorPY, String searchStr) {
        
        String[] arr = separatorPY.split(",");
        int prefixPoint = 0;
        int len = 0;
        int slen = searchStr.length();
        SiteObj obj = new SiteObj();
        if (arr != null) {
            for (int i = 0; i < arr.length; ++i) {
                String checkStr = arr[i].trim();
                len = checkStr.length();
                if (len > (slen - prefixPoint)) {
                    if (checkStr.startsWith(searchStr.substring(prefixPoint))) {
                        obj.setEndPoint(i);
                        if (obj.getBeginPoint() == -1) {
                            obj.setBeginPoint(i);
                        }
                        return obj;
                    } else {
                        if (obj.getBeginPoint() != -1)
                            return null;
                    }
                } else {
                    if (searchStr.startsWith(checkStr, prefixPoint)) {
                        if (obj.getBeginPoint() == -1) {
                            obj.setBeginPoint(i);
                        }
                        prefixPoint += len;
                        if (prefixPoint >= slen) {
                            obj.setEndPoint(i);
                            return obj;
                        }
                    }
                }
            }
        }
        return null;
    }
    
    public static SiteObj GetQuanPYSite(String fullpy, String separatorPY, String searchStr) {
        if (NullUtils.isEmpty(searchStr)) {
            return null;
        }
        if (!fullpy.contains(searchStr)) {
            return null;
        }
      return   GetQuanPYSite(separatorPY, searchStr);
//        String[] arr = separatorPY.split(",");
//        int prefixPoint = 0;
//        int len = 0;
//        int slen = searchStr.length();
//        SiteObj obj = new SiteObj();
//        if (arr != null) {
//            for (int i = 0; i < arr.length; ++i) {
//                String checkStr = arr[i].trim();
//                String searchValue=searchStr.substring(prefixPoint);
//                if (searchValue.startsWith(checkStr)) {
//                    if (prefixPoint==0) {
//                        obj.setBeginPoint(i);
//                    }
//                    prefixPoint+=checkStr.length();
//                    if (prefixPoint==searchStr.length()-1) {
//                        obj.setEndPoint(i);
//                    }
//                    continue;
//                }else if(checkStr.startsWith(searchValue)){
//                    if (prefixPoint==0) {
//                        obj.setBeginPoint(i);
//                    }
//                    obj.setEndPoint(i);
//                }
//          
//            }
//        }
    }
    
    public static SiteObj GetOtherSite(String dataStr, String searchStr) {
        int point = dataStr.indexOf(searchStr);
        if (point > -1) {
            SiteObj obj = new SiteObj();
            obj.setBeginPoint(point);
            obj.setEndPoint(point + searchStr.length() - 1);
            return obj;
        }
        return null;
    }
    
}
